#include <iostream>
#include <string>
#include <unistd.h>
#include <cstring>
#include <netinet/in.h>
#include <sys/types.h>
#include <strings.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <memory>
#include "Log.hpp"
#include <unordered_map>
#include <fstream>
enum
{
    SOCK_ERR = 1,
    BIND_ERR,
    RECV_ERR,
    SENDTO_ERR
};
class socket_basic
{
public:
    socket_basic(uint16_t port, in_addr_t ip)
    {
        _sockfd = socket(AF_INET, SOCK_DGRAM, 0);
        if (_sockfd < 0)
        {
            _log(FATAL,__LINE__,__FILE__,"create socket error!\n");
            exit(SOCK_ERR);
        }
        memset(&_addr, 0, sizeof(_addr));
        _addr.sin_addr.s_addr = ip;
        _addr.sin_family = AF_INET;
        _addr.sin_port = htons(port);
    }
    struct sockaddr_in GetSockaddr()
    {
        return _addr;
    }
    int GetSockfd()
    {
        return _sockfd;
    }

protected:
    int _sockfd;
    struct sockaddr_in _addr;
    LogType _log;
};
